//
//  ContentView.swift
//  Co2DappHackson
//
//  Created by zhao on 2023/11/5.
//

import SwiftUI
import Combine
import metamask_ios_sdk

struct ContentView: View {
    
    @StateObject  var mettaMaskRepo = MetaMaskRepo()
    @State private var status = "Offline"
   
    
    var body: some View {
        VStack(alignment: .leading, spacing: 32) {
            Text("Co2 dapp")
                .font( .title)
            
            Text("Status: \(mettaMaskRepo.connectionStatus)")
                .fontWeight(.bold)
            
            Text("Chainid:  \(mettaMaskRepo.chainID) ")
                .fontWeight(.bold)
            
            Text("Account:  \(mettaMaskRepo.ethAddress) ")
                .fontWeight(.bold)
            
//            Text(mettaMaskRepo.etherum.selectedAddress)
//                .fontWeight(.bold)
            
            Button{
                mettaMaskRepo.connectToDapp()
            } label: {
                Text("connect to MetaMask")
                    .frame(width: 300,height: 50)
                    .border(.black)
            }
            .buttonStyle(.borderedProminent)
            
            Text("Balance: \(mettaMaskRepo.balance)")
                .fontWeight(.bold)
            
            
            Button{
                mettaMaskRepo.getBalance()
            } label: {
                Text("Get balance")
                    .frame(width: 300,height: 50)
                    .border(.black)
            }
            .buttonStyle(.borderedProminent)
            
            Text("Steps: \(mettaMaskRepo.stepCount)")
                .fontWeight(.bold)
            
            Button{
                mettaMaskRepo.authHealth()
            } label: {
                Text("Get Steps")
                    .frame(width: 300,height: 50)
                    .border(.black)
            }
            .buttonStyle(.borderedProminent)
            
            Button{
                mettaMaskRepo.callContract()
            } label: {
                Text("Get smart contract")
                    .frame(width: 300,height: 50)
                    .border(.black)
            }
            .buttonStyle(.borderedProminent)
            
            Button{
                mettaMaskRepo.send()
            } label: {
                Text("Send transaction")
                    .frame(width: 300,height: 50)
                    .border(.black)
            }
            .buttonStyle(.borderedProminent)
            
            Spacer()
        }
        .padding()
    }
}

#Preview {
    ContentView()
}
